<template>
  <div>
    <Modeler ref="modeler" :bpmnXml="modelXml" @submit="submitData"></Modeler>
  </div>
</template>

<script>
import Modeler from "@/components/activit/components/Modeler";
import {getModelEditorSource, saveModelEditorSource} from "@/api/start/activiti/modelApi";
import {createEmptyTemplate} from "@/components/activit/components/BpmnUtils";
import {getActModelConfigDetail} from "../../api/start/activiti/modelApi";

export default {
  name: "index_1_1",
  components: {
    Modeler
  },
  data() {
    return {
      modelId: null,
      modelXml: null,
    }
  },
  created() {
    this.init();
  },
  methods: {
    init() {
      this.modelId = this.$route.query.modelId
      if (!this.modelId) this.modelId = this.$route.params.modelId
      this.loadModel();
    },
    loadModel() {
      getActModelConfigDetail(this.modelId).then(res => {
        let data = res.data.data;
        if (!data) {
          data = {};
          data.modelConfig = {};
          data.nodeForms = [];
          data.nodeAssignees = [];
        }

        if (!data.bpmnXml) {
          data.bpmnXml = createEmptyTemplate(data.activitiModel.key,data.activitiModel.name)
        }
        console.log(data)
        this.$refs.modeler.loadBpmnXML(data.bpmnXml, data.modelConfig, data.nodeAssignees, data.nodeForms);
      })
    },
    submitData(data) {
      saveModelEditorSource(this.modelId, data).then(res => {
        console.log(res.data.data)
      })
    }
  }
}
</script>

<style scoped>

</style>
